/*
 * 
 * 
 */
package DigimonAdventure.Things;

import DigimonAdventure.Database.Acc;
import DigimonAdventure.Database.Armor;
import DigimonAdventure.Database.Boost;
import DigimonAdventure.Database.DigimonSpecies;
import DigimonAdventure.Database.Direction;
import DigimonAdventure.Database.Item;
import DigimonAdventure.Database.Loots;
import DigimonAdventure.Database.Shield;
import DigimonAdventure.Database.Weapon;
import java.util.ArrayList;
import javax.swing.ImageIcon;

/**
 *
 * @author Kris Derril Siregar
 */
public final class Player extends AbstractThings {

    private String nama;
    private int GenderCode;
    private int DigiSeq;
    private DigimonBaik[] ownDigimon = new DigimonBaik[3]; //hati-hati, array bisa diassign aja yang kosong diisi null
    private ArrayList<Loots> invLoot = new ArrayList<Loots>(10);
    private ArrayList<Item> invItem = new ArrayList<Item>(10);
    private ArrayList<Weapon> invWeapon = new ArrayList<Weapon>(5);
    private ArrayList<Armor> invArmor = new ArrayList<Armor>(5);
    private ArrayList<Shield> invShield = new ArrayList<Shield>(5);
    private ArrayList<Boost> invBoost = new ArrayList<Boost>(5);
    private ArrayList<Acc> invAcc = new ArrayList<Acc>(5);
    private int bit;
    private int activeDigimon;

    public Player(int x, int y, String nama) {
        super(x, y);
        this.nama = nama;
        activeDigimon = 0;
        for (int i = 0; i < ownDigimon.length; i++) {
            ownDigimon[i] = null;
        }
    }

    public Player() {
        bit = 2000;
        invItem.add(Item.exp1);
    }

    /**
     * @return
     */
    public DigimonBaik getActiveDigimon() {
        return ownDigimon[activeDigimon];
    }

    public void setActiveDigimon(int i) throws ArrayIndexOutOfBoundsException {
        if (ownDigimon[i] != null) {
            activeDigimon = i;
        }
    }

    public synchronized void nextDigimon() {
        if (activeDigimon == 2) {
            activeDigimon = 0;
            if (getActiveDigimon() == null) {
                activeDigimon = 2;
            }
        } else {
            activeDigimon++;
            if (getActiveDigimon() == null) {
                activeDigimon--;
            }
        }
    }

    public DigimonBaik[] getListDigimon() {
        return ownDigimon;
    }

    public ArrayList<Item> getListItem() {
        return invItem;
    }

    public Item getItemAt(int x) {
        if (invItem.size() <= x || invItem.get(x) == null) {
            return Item.None;
        } else {
            return invItem.get(x);
        }
    }

    public ArrayList<Loots> getListLoot() {
        return invLoot;
    }

    public Loots getLootAt(int x) {
        if (invLoot.size() <= x || invLoot.get(x) == null) {
            return Loots.None;
        } else {
            return invLoot.get(x);
        }
    }

    public ArrayList<Weapon> getListWeapon() {
        return invWeapon;
    }

    public Weapon getWeaponAt(int x) {
        if (invWeapon.size() <= x || invWeapon.get(x) == null) {
            return Weapon.None;
        } else {
            return invWeapon.get(x);
        }
    }

    public ArrayList<Armor> getListArmor() {
        return invArmor;
    }

    public Armor getArmorAt(int x) {
        if (invArmor.size() <= x || invArmor.get(x) == null) {
            return Armor.None;
        } else {
            return invArmor.get(x);
        }
    }

    public ArrayList<Shield> getListShield() {
        return invShield;
    }

    public Shield getShieldAt(int x) {
        if (invShield.size() <= x || invShield.get(x) == null) {
            return Shield.None;
        } else {
            return invShield.get(x);
        }
    }

    public ArrayList<Boost> getListBoost() {
        return invBoost;
    }

    public Boost getBoostAt(int x) {
        if (invBoost.size() <= x || invBoost.get(x) == null) {
            return Boost.None;
        } else {
            return invBoost.get(x);
        }
    }

    public ArrayList<Acc> getListAcc() {
        return invAcc;
    }

    public Acc getAccAt(int x) {
        if (invAcc.size() <= x || invAcc.get(x) == null) {
            return Acc.None;
        } else {
            return invAcc.get(x);
        }
    }

    public String getNama() {
        return nama;
    }

    public int getBit() {
        return bit;
    }

    public void setNama(String nama) {
        this.nama = nama;
    }

    public void addBit(int cash) {
        this.bit += cash;
    }

    public void redBit(int cash) {
        this.bit -= cash;
    }

    /**
     * Menambahkan & Membuang benda2 di inventory
     * Masih problematic sama IndexOutofBoundsException
     */
    public void addItem(Item i) {
        if (i != Item.None) {
            invItem.add(i);
        }
    }

    public void remItemAt(int i) {
        if (invItem.size() < i || invItem.get(i) == null) {
        } else {
            invItem.remove(i);
        }
    }

    public void addLoot(Loots i) {
        if (i != Loots.None) {
            invLoot.add(i);
        }
    }

    public void remLootAt(int i) {
        if (invLoot.size() < i || invLoot.get(i) == null) {
        } else {
            invLoot.remove(i);
        }
    }

    public void addArmor(Armor i) {
        if (i != Armor.None) {
            invArmor.add(i);
        }
    }

    public void remArmorAt(int i) {
        if (invArmor.size() < i || invArmor.get(i) == null) {
        } else {
            invArmor.remove(i);
        }
    }

    public void addWeapon(Weapon i) {
        if (i != Weapon.None) {
            invWeapon.add(i);
        }
    }

    public void remWeaponAt(int i) {
        if (invWeapon.size() < i || invWeapon.get(i) == null) {
        } else {
            invWeapon.remove(i);
        }
    }

    public void addShield(Shield i) {
        if (i != Shield.None) {
            invShield.add(i);
        }
    }

    public void remShieldAt(int i) {
        if (invShield.size() < i || invShield.get(i) == null) {
        } else {
            invShield.remove(i);
        }
    }

    public void addBoost(Boost i) {
        if (i != Boost.None) {
            invBoost.add(i);
        }
    }

    public void remBoostAt(int i) {
        if (invBoost.size() < i || invBoost.get(i) == null) {
        } else {
            invBoost.remove(i);
        }
    }

    public void addAcc(Acc i) {
        if (i != Acc.None) {
            invAcc.add(i);
        }
    }

    public void remAccAt(int i) {
        if (invAcc.size() < i || invAcc.get(i) == null) {
        } else {
            invAcc.remove(i);
        }
    }

    /**
     * Menambah digimon baru berdasarkan <b>spesiesnya. </b><>
     * Segala atribut diset seperti <b>digimon bayi</b>
     * @param species
     */
    public void addDigimon(DigimonSpecies species) {
        if (ownDigimon[0] == null) {
            ownDigimon[0] = new DigimonBaik(species);
        } else if (ownDigimon[1] == null) {
            ownDigimon[1] = new DigimonBaik(species);
        } else if (ownDigimon[2] == null) {
            ownDigimon[2] = new DigimonBaik(species);
        }
        //digimon full (sudah 3) , tidak bisa nambah lagi
    }

    /**
     * Ngebersihin list digimon milik player
     * Buat new game
     */
    public void remAllDigimon() {
        this.getListDigimon()[0] = null;
        this.getListDigimon()[1] = null;
        this.getListDigimon()[2] = null;
    }

    /**
     * Mengeset gender player, gender disimbolkan oleh icon player
     * @param gender
     */
    public void setGender(String gender) {
        if ("male".equals(gender)) {
            this.icon = new ImageIcon(getClass().getResource("/DigimonAdventure/Graphics/FaceM.gif"));
            GenderCode = 1;
        } else if ("female".equals(gender)) {
            this.icon = new ImageIcon(getClass().getResource("/DigimonAdventure/Graphics/FaceF.gif"));
            GenderCode = 0;
        } else {
            this.icon = new ImageIcon(getClass().getResource("/DigimonAdventure/Graphics/Mir2.gif"));
            GenderCode = 3;
        }
    }

    public int getGenderCode() {
        return GenderCode;
    }

    /**Mengambil sequence pengambilan digimon*/
    public int getDigiSeq() {
        return DigiSeq;
    }

    /**Menentukan sequence pengambilan digimon*/
    public void setDigiSeq(int DS) {
        DigiSeq = DS;
    }

    @Override
    public void move(Direction arah) {
        switch (arah) {
            case ATAS:
                if (titik.x == 1) {
                } else {
                    this.titik.y--;
                }
                break;
            case BAWAH:
                if (titik.y == 20) {
                } else {
                    this.titik.y++;
                }
                break;
            case KANAN:
                if (titik.x == 40) {
                } else {
                    this.titik.x++;
                }
                break;
            case KIRI:
                if (titik.x == 1) {
                } else {
                    titik.x--;
                }
                break;
            default:
        }
    }

    /**
     * Mengembalikan icon dari player
     * @return
     */
    @Override
    public ImageIcon getImageIcon() {
        if (icon != null) {
            return icon;
        } else {
            throw new NullPointerException();
        }

    }

    /**
     * Driver
     * @param args
     */
    public static void main(String[] args) {
        Player tes = new Player();

    }
}
